﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FiyatGor
{
    public partial class frmListe : Form
    {
        public string StokKod { get; set; }
        public string StokAdi { get; set; }

        public enum ListeTipleri : byte
        {
            StokKodundan,
            StokAdindan
        }
        public ListeTipleri ListeTipi { get; set; }
        public string Filtre { get; set; }

        public frmListe()
        {
            InitializeComponent();
            this.Load += new EventHandler(frmListe_Load);
        }

        void frmListe_Load(object sender, EventArgs e)
        {
            this.Filtre = this.Filtre.Replace('*', '%');
            if (string.IsNullOrEmpty(this.Filtre)) this.Filtre = "%";

            switch (ListeTipi)
            {
                case ListeTipleri.StokAdindan:
                    gridControl1.DataSource = DataLayer.Get.Fill(string.Format("SELECT     sto_kod AS [Stok Kodu], sto_isim AS [Stok Adı] FROM         STOKLAR WHERE     (sto_isim LIKE '{0}')", Filtre));
                    break;
                case ListeTipleri.StokKodundan:
                    gridControl1.DataSource = DataLayer.Get.Fill(string.Format("SELECT     sto_kod AS [Stok Kodu], sto_isim AS [Stok Adı] FROM         STOKLAR WHERE     (sto_kod LIKE '{0}')", Filtre));
                    break;
                default:
                    break;
            }
            gridView1.BestFitColumns();
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            if (gridView1.RowCount > 0)
            {
                this.StokKod = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString();
                this.StokAdi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[1]).ToString();
                this.DialogResult = DialogResult.OK;
            }
            this.Close();
        }

        private void gridControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (gridView1.RowCount > 0)
                {
                    this.StokKod = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString();
                    this.StokAdi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[1]).ToString();
                    this.DialogResult = DialogResult.OK;
                }
                this.Close();
            }
        }


    }
}
